package org.chaiyi.template.core.common.util.asserts;

import cn.hutool.core.util.CharUtil;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Asserts {
    private Asserts() {
    }

    public static BigDecimalAssert of(BigDecimal value) {
        return new BigDecimalAssert(value);
    }

    public static boolean lt(BigDecimal number01, BigDecimal number02) {
        return (new BigDecimalAssert(number01)).lt(number02);
    }

    public static boolean lte(BigDecimal number01, BigDecimal number02) {
        return (new BigDecimalAssert(number01)).lte(number02);
    }

    public static boolean gte(BigDecimal number01, BigDecimal number02) {
        return (new BigDecimalAssert(number01)).gte(number02);
    }

    public static boolean gt(BigDecimal number01, BigDecimal number02) {
        return (new BigDecimalAssert(number01)).gt(number02);
    }

    public static boolean eq(BigDecimal number01, BigDecimal number02) {
        return (new BigDecimalAssert(number01)).eq(number02);
    }

    public static boolean in(BigDecimal number, BigDecimal from, BigDecimal to) {
        return (new BigDecimalAssert(number)).in(from, to);
    }

    public static boolean zero(BigDecimal value) {
        return (new BigDecimalAssert(value)).zero();
    }

    public static DateAssert of(Date value) {
        return new DateAssert(value);
    }

    public static boolean lt(Date date01, Date date02) {
        return (new DateAssert(date01)).lt(date02);
    }

    public static boolean lte(Date date01, Date date02) {
        return (new DateAssert(date01)).lte(date02);
    }

    public static boolean gte(Date date01, Date date02) {
        return (new DateAssert(date01)).gte(date02);
    }

    public static boolean gt(Date date01, Date date02) {
        return (new DateAssert(date01)).gt(date02);
    }

    public static boolean in(Date date, Date from, Date to) {
        return (new DateAssert(date)).in(from, to);
    }

    public static boolean timeRange(Date date, Date form, Date to) {
        return (new DateAssert(date)).timeRange(form, to);
    }

    public static LocalDateTimeAssert of(LocalDateTime value) {
        return new LocalDateTimeAssert(value);
    }

    public static boolean lt(LocalDateTime date01, LocalDateTime date02) {
        return (new LocalDateTimeAssert(date01)).lt(date02);
    }

    public static boolean lte(LocalDateTime date01, LocalDateTime date02) {
        return (new LocalDateTimeAssert(date01)).lte(date02);
    }

    public static boolean gte(LocalDateTime date01, LocalDateTime date02) {
        return (new LocalDateTimeAssert(date01)).gte(date02);
    }

    public static boolean gt(LocalDateTime date01, LocalDateTime date02) {
        return (new LocalDateTimeAssert(date01)).gt(date02);
    }

    public static boolean in(LocalDateTime date, LocalDateTime from, LocalDateTime to) {
        return (new LocalDateTimeAssert(date)).in(from, to);
    }

    public static boolean timeRange(LocalDateTime date, LocalDateTime form, LocalDateTime to) {
        return (new LocalDateTimeAssert(date)).timeRange(form, to);
    }

    public static boolean in(String actual, String... expect) {
        return Arrays.asList(expect).contains(actual);
    }

    public static boolean notIn(String actual, String... expect) {
        return !Arrays.asList(expect).contains(actual);
    }

    public static boolean eq(Object obj01, Object obj02) {
        return Objects.equals(obj01, obj02);
    }

    public static boolean ne(Object obj01, Object obj02) {
        return !Objects.equals(obj01, obj02);
    }

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }


    public static boolean isEmpty(Object[] objects) {
        return objects == null || objects.length == 0;
    }

    public static boolean isBlank(CharSequence str) {
        int length;
        if (str != null && (length = str.length()) != 0) {
            for (int i = 0; i < length; ++i) {
                if (!CharUtil.isBlankChar(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }

    public static boolean isNotBlank(CharSequence value) {
        return !isBlank(value);
    }

    public static boolean notBlank(CharSequence value) {
        return !isBlank(value);
    }

    public static boolean notEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

    public static boolean notNull(Object object) {
        return object != null;
    }

    public static boolean minSize(Collection<?> collection, int minSize) {
        return !isEmpty(collection) && collection.size() >= minSize;
    }

    public static boolean minSize(Map<?, ?> map, int minSize) {
        return !isEmpty(map) && map.size() >= minSize;
    }

    public static boolean pattern(CharSequence value, CharSequence regex) {
        Pattern pattern = Pattern.compile(regex.toString());
        Matcher m = pattern.matcher(value.toString());
        return m.matches();
    }

    public static boolean contains(Collection<?> collection, Object item) {
        return collection != null && collection.contains(item);
    }

    public static boolean hasNull(Object... args) {
        for (Object arg : args) {
            if (null == arg) return true;
        }
        return false;
    }
}
